<?php

use yii\db\Migration;

class m180508_061411_create_customer_relationship_log extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%customer_tracking_record}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'name' => $this->string(255)->defaultValue(null)->comment('客户姓名'),
                'status' => $this->integer()->defaultValue(0)->comment('状态：潜在客户-未注册、意向客户-已注册、正式VIP-购买产品'),
                'mobile' => $this->string(255)->defaultValue(null)->comment('客户联系方式'),
                'created_at' => $this->integer(11)->defaultValue(0)->comment('创建时间'),
                'details' => $this->string(255)->defaultValue(null)->comment('跟踪详情'),
                'results' => $this->string(255)->defaultValue(null)->comment('处理结果'),
                'admin_id' => $this->smallInteger()->defaultValue(0)->comment('负责人id'),
                'relationship_id' => $this->smallInteger()->defaultValue(0)->comment('customer_relationship id'),
                'current_time' => $this->integer(11)->defaultValue(0)->comment('本次约谈时间'),
                'next_time' => $this->integer(11)->defaultValue(0)->comment('下次约谈时间'),
                'tracking_status' => $this->integer()->defaultValue(0)->comment('跟进方式状态'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%customer_tracking_record}}');
        }
    }
}
